package com.bdgls.java8.ConsumerTest;

import java.util.function.Consumer;
import java.util.function.Predicate;

/**
 * Created by yibo on 2016-6-21.
 */
public class PreidcateConsumerDemo {

    public static void main(String[] args) {


        Student student1 = new Student("Ashok", "Kumar", 7.5);

        student1.printFee();
        student1 = updateStudentFee(student1,

                //Lambda expression for Predicate interface

                student -> student.grade > 8.5,

                //Lambda expression for Consumer inerface

                student -> student.feeDiscount = 30.0);


        student1.printFee();


//        Student student2 = new Student("Rajat", "Verma", 8.0);
//
//
//        student2 = updateStudentFee(student2,
//
//                student -> student.grade >= 8,
//
//                student -> student.feeDiscount = 20.0);
//
//
//        student2.printFee();


    }

    public static Student updateStudentFee(Student student, Predicate<Student> predicate, Consumer<Student> consumer) {


        //Use the predicate to decide when to update the discount.
        if (predicate.test(student)) {
            //Use the consumer to update the discount value.
            consumer.accept(student);
        }


        return student;


    }


}
